package top.liuzhenyu.springboot3.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.liuzhenyu.springboot3.base.PageBean;
import top.liuzhenyu.springboot3.base.R;
import top.liuzhenyu.springboot3.entity.TbGame;
import top.liuzhenyu.springboot3.service.TbGameService;
import top.liuzhenyu.springboot3.vo.PageVO;

@RestController
@RequiredArgsConstructor
@RequestMapping("/game")
public class TbGameController {
    private final TbGameService tbGameService;

    @PostMapping("")
    public R<String> insert(@RequestBody TbGame tbGame) {
        return tbGameService.insert(tbGame);
    }

    @GetMapping("/{ps}/{pn}")
    public R<PageVO<TbGame>> query(@PathVariable("ps") Long pageSize, @PathVariable("pn") Long pageNumber,
                                   TbGame tbGame) {
        return tbGameService.query(tbGame, PageBean.instance(pageSize, pageNumber));
    }

    @GetMapping("/{id}")
    public R<TbGame> queryByKey(@PathVariable("id") Integer id) {
        return tbGameService.queryByKey(id);
    }

    @PutMapping("")
    public R<String> update(@RequestBody TbGame tbGame) {
        return tbGameService.update(tbGame);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return tbGameService.delete(id);
    }
}
